<?php
class VideoHelper {
	static public function GetVideoInformation($file) {
		if (!file_exists($file)) {
			return FALSE;
		}
		$command = "/usr/bin/mediainfo -f --Language=raw {$file}";
		exec($command, $command_output, $ret);
		
		$information = array();
		$current_section = '';
		foreach ($command_output as $line) {
			$line = trim($line);
			if ($line == "") {
				continue;
			}

			$tmp = explode(" : ", $line);
			if (count($tmp) == 1) {
				$current_section = $tmp[0];
			} else {
				$information[$current_section][trim($tmp[0])] = trim($tmp[1]);
			}			
		}

		return $information;
	}

	static public function Capture($file, $image_file, $time) {
		$command = "/opt/ffmpeg/bin/ffmpeg -y -v 0 -i {$file} -ss {$time} -vframes 1 -f image2 {$image_file}";
		exec($command, $command_output, $ret);
		
		return ($ret === 0);
	}
}
?>
